package cn.tedu.csmall.server.controller;

import cn.tedu.csmall.server.pojo.dto.BrandAddNewDTO;
import cn.tedu.csmall.server.pojo.dto.BrandEditDTO;
import cn.tedu.csmall.server.service.IBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/brands")
public class BrandController {

    @Autowired
    private IBrandService brandService;

    public BrandController(){
        System.out.println("品牌控制器层对象.BrandController()");
    }

    // localhost:8080/brands/add-new?name=罗技&pinyin=luoji&...
    @RequestMapping("/add-new")
    public String addNew(BrandAddNewDTO brandAddNewDTO){
        System.out.println("BrandController.addNew()");
        System.out.println("品牌名称："+brandAddNewDTO.getName()+",品牌拼音："+brandAddNewDTO.getPinyin());
        return "add-new";
    }

    // 访问 localhost:8080/brands/9527/delete
    @RequestMapping("/{id}/delete")
    public String delete(@PathVariable Long id){
        System.out.println("BrandController.delete()");
        System.out.println("根据id="+id+"删除类别");
        return "del";
    }

    // 传统传参：localhost:8080/brands/update?id=9527&name=...
    // RESTful传参：localhost:8080/brands/9527/update?name=...
    @RequestMapping("/{id:[0-9]+}/update")
    public String edit(@PathVariable("id") Long brandId, BrandEditDTO brandEditDTO){
        System.out.println("BrandController.edit()");
        System.out.println("根据数字id="+brandId+"修改类别");
        return "update";
    }


    //访问路径： localhost:8080/brands
//    @GetMapping("")
    @GetMapping
    public String list(){
        System.out.println("BrandController.list()");
        return "list";
    }
}
